home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: howland.reston.ans.net!torn!nott!emr1!jagrant
- From: jagrant@emr1.emr.ca (John Grant)
- Subject: simple design question
- Message-ID: <DM4u8I.G1H@emr1.emr.ca>
- Organization: Energy, Mines, and Resources, Ottawa
- Date: Fri, 2 Feb 1996 05:07:30 GMT
-
- This is a design question, not a syntax question, so forgive the pseudo-
- code.
-
- I'm trying to design/write a class for complex file I/O (I'll state it
- in simple terms here).
-
- I want to use it like this:
- object.Open("xxx")
- for(...){
- object.Read(stuff);
- }
- object.Close();
-
- But I want to also have a single function that will Open/Read/Close in a
- single operation:
- object.GetData("xxx",stuff);
-
- The simple question is: should I implement GetData() as part of this
- class, i.e.:
- int myclass::GetData(...){
- { Open()
- Read()
- Close()
- }
-
- or should GetData() really be in a separate class which uses the first class:
- int myclass2::GetData(...)
- { myclass *object=new myclass;
- object->Open(...)
- object->Read(...)
- object->Close(...);
- delete object;
- }
-
- If so, is that the best way to do it, or is there a slicker C++ way to do
- that using inheritance etc (which I am just trying to figure out).
-
- The reason I ask, is the potential for conflict in the use of the
- private variables. For example, internally there might be:
- private: FILE *f;
- <...more internals...>
-
- If I used it incorrectly, i.e.:
- object.Open(...)
- object.GetData(...) //does Open/Read/Close
- object.Read(...)
- then object.Read() would break because GetData() calls Close(), invalidating
- 'f' and other internals.
- --
- John A. Grant jagrant@emr1.emr.ca
- Airborne Geophysics
- Geological Survey of Canada, Ottawa
-